const express = require('express');
const conn =require("./mysql.js")
const app = express();
// const users = [{ username: 'admin', password: 'password123' }];
app.get("/login",(req,res)=>{
    conn.connect((err)=>{
        if(err){
            console.error("1."+err.message);

        }else{
            console.log("1.连接成功")
        }
    })
    let sql ="select * from user where username = '" + req.query.uname+"' and password = '" + req.query.upwd + "';"
   conn.query(sql ,(err,result)=>{
    if(err){
        console.error("2."+err.message);
    }else{
        console.log(result)
        if(result.length>0){
            res.json({code:200,msg:"登录成功"})
        }else{
            res.json({code:401,msg:"用户名或密码错误"})
        }
    }
   })
    //   let user =users.find(u=>u.username==req.query.uname && u.password==req.query.upwd)
//   console.log(user)
//   if(user){
//     res.json({code:200,msg:"登录成功"})
//   } else{
//     res.json({code:401,msg:"用户名或密码错误"})
//   }

})
app.listen(8080, () => {
 console.log('8000端口已启动');
 });

